/* GTKMM plugin for VLC */

#ifdef HAVE_CONFIG_H
#include "config.h"
#endif

#include "components/interface_widgets.hh"

#include <gtkmm/alignment.h>
#include <gtkmm/calendar.h>
#include <gtkmm/image.h>

#include <vlc_aout.h>

#include "gtkmm.hh"
#include "pixmaps/resources.h"
#include "util/string.hh"
#include "vlcmm/soundcontrol.h"

#include <iostream>

#define VOLUME_MAX 200

ControlsWidget::ControlsWidget (intf_thread_t *_p_i) : 
  p_intf (_p_i),
  playButton (),
  slider (0.0, 100.0, 1.0)
{

  slider.set_draw_value (false);
  pack_start (*&slider);

  Gtk::HBox *control_box = new Gtk::HBox (false, 2);
  control_box->set_border_width (8);

  playButton.set_image (*Gtk::manage (new Gtk::Image (Gdk::Pixbuf::create_from_inline (-1, vlc_media_play))));
  playButton.set_focus_on_click (false);
  playButton.set_relief (Gtk::RELIEF_NONE);
  playButton.set_has_tooltip (true);
  playButton.set_tooltip_text (_("Play"));
  control_box->pack_start (*&playButton, false, false);
  playButton.signal_clicked ().connect (sigc::mem_fun (this, &ControlsWidget::play));

  Gtk::HBox *hbox = new Gtk::HBox (false, 2);

  Gtk::Alignment *alignment = new Gtk::Alignment (1.0, 1.0, 0.0, 0.0);
  alignment->add (*Gtk::manage (hbox));

  Gtk::Button *button = new Gtk::Button ();
  button->set_image (*Gtk::manage (new Gtk::Image (Gdk::Pixbuf::create_from_inline (-1, vlc_media_prev))));
  button->set_focus_on_click (false);
  button->set_relief (Gtk::RELIEF_NONE);
  button->set_has_tooltip (true);
  button->set_tooltip_text (_("Play"));
  hbox->pack_start (*Gtk::manage (button), false, false);

  button = new Gtk::Button ();
  button->set_image (*Gtk::manage (new Gtk::Image (Gdk::Pixbuf::create_from_inline (-1, vlc_media_stop))));
  button->set_focus_on_click (false);
  button->set_relief (Gtk::RELIEF_NONE);
  hbox->pack_start (*Gtk::manage (button), false, false);

  button = new Gtk::Button ();
  button->set_image (*Gtk::manage (new Gtk::Image (Gdk::Pixbuf::create_from_inline (-1, vlc_media_next))));
  button->set_focus_on_click (false);
  button->set_relief (Gtk::RELIEF_NONE);
  hbox->pack_start (*Gtk::manage (button), false, false);

  hbox->pack_start (*Gtk::manage (new Gtk::HBox()), true, true, 6);

  button = new Gtk::Button ();
  button->set_image (*Gtk::manage (new Gtk::Image (Gdk::Pixbuf::create_from_inline (-1, vlc_fullscreen))));
  button->set_focus_on_click (false);
  button->set_relief (Gtk::RELIEF_NONE);
  button->signal_clicked ().connect(sigc::mem_fun (this, &ControlsWidget::fullscreen));
  hbox->pack_start (*Gtk::manage (button), false, false);
  
  button = new Gtk::Button ();
  button->set_image (*Gtk::manage (new Gtk::Image (Gdk::Pixbuf::create_from_inline (-1, vlc_playlist))));
  button->set_focus_on_click (false);
  button->set_relief (Gtk::RELIEF_NONE);
  hbox->pack_start (*Gtk::manage (button), false, false);
  
  button = new Gtk::Button ();
  button->set_image (*Gtk::manage (new Gtk::Image (Gdk::Pixbuf::create_from_inline (-1, vlc_ext_settings))));
  button->set_focus_on_click (false);
  button->set_relief (Gtk::RELIEF_NONE);
  hbox->pack_start (*Gtk::manage (button), false, false);

  hbox->pack_start (*Gtk::manage (new Gtk::HBox()), true, true, 6);

  Vlc::SoundControl *sound_control = new Vlc::SoundControl ();
  sound_control->signal_value_changed ().connect(sigc::mem_fun (this, &ControlsWidget::updateVolume));
  hbox->pack_start (*Gtk::manage (sound_control), false, false);

  control_box->pack_start (*Gtk::manage (alignment), false, false);

  pack_start (*Gtk::manage (control_box), false, false);  

}

ControlsWidget::~ControlsWidget ()
{}

void
ControlsWidget::play ()
{

  if (THEPL->current.i_size == 0)
   {
    std::cout << "No playing file open OpenDialog !" << std::endl;   
   }


}

void
ControlsWidget::stop ()
{}

void
ControlsWidget::updateVolume (double value)
{

  aout_VolumeSet (p_intf, (int)value  * (AOUT_VOLUME_MAX / 2) / VOLUME_MAX);

}

void
ControlsWidget::fullscreen ()
{

  vout_thread_t *p_vout = (vout_thread_t *)vlc_object_find (p_intf, VLC_OBJECT_VOUT, FIND_ANYWHERE);
  
  if (p_vout)
   {
    var_SetBool (p_vout, "fullscreen", !var_GetBool (p_vout, "fullscreen"));
    vlc_object_release (p_vout);
   }

}

